package kr.co.doriclassic.chapter18;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridLayout;

public class PanelJDialog extends JPanel implements ActionListener {
	private JButton btnMessage01;
	private JButton btnMessage02;
	private JButton btnMessage03;
	private JButton btnMessage04;
	private JButton btnMessage05;
	private JButton btnMessage06;

	/**
	 * Create the panel.
	 */
	public PanelJDialog() {

		initialize();
	}
	private void initialize() {
		
		btnMessage02 = new JButton("show message dialog(error)");
		btnMessage02.addActionListener(this);
		
		btnMessage01 = new JButton("show message dialog(warnning)");
		btnMessage01.addActionListener(this);
		setLayout(new GridLayout(0, 1, 0, 0));
		add(btnMessage01);
		add(btnMessage02);
		
		btnMessage03 = new JButton("show message dialog(Option Dialog_yesnocancle)");
		btnMessage03.addActionListener(this);
		add(btnMessage03);
		
		btnMessage04 = new JButton("show message dialog(Option Dialog_yesno)");
		btnMessage04.addActionListener(this);
		add(btnMessage04);
		
		btnMessage05 = new JButton("show input dialog(ComboBox)");
		btnMessage05.addActionListener(this);
		add(btnMessage05);
		
		btnMessage06 = new JButton("show input dialog(TextField)");
		btnMessage06.addActionListener(this);
		add(btnMessage06);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnMessage06) {
			actionPerformedBtnMessage06(e);
		}
		if (e.getSource() == btnMessage05) {
			actionPerformedBtnMessage05(e);
		}
		if (e.getSource() == btnMessage04) {
			actionPerformedBtnMessage04(e);
		}
		if (e.getSource() == btnMessage03) {
			actionPerformedBtnMessage03(e);
		}
		if (e.getSource() == btnMessage02) {
			actionPerformedBtnMessage02(e);
		}
		if (e.getSource() == btnMessage01) {
			actionPerformedBtnMessage(e);
		}
	}
	protected void actionPerformedBtnMessage(ActionEvent e) {
		JOptionPane.showMessageDialog(this, "범위초과", "경고", JOptionPane.WARNING_MESSAGE);
	}
	protected void actionPerformedBtnMessage02(ActionEvent e) {
		JOptionPane.showMessageDialog(this, "범위초과", "경고", JOptionPane.ERROR_MESSAGE);
	}
	protected void actionPerformedBtnMessage03(ActionEvent e) {
		String[] options = {"Well Done", "Medium", "Rare"};
		int res = JOptionPane.showOptionDialog(this, "스테이크를 어떻게 요리할까요?", "스테이크 주문", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
		JOptionPane.showMessageDialog(null, options[res]+"선택하셨습니다");
	}
	protected void actionPerformedBtnMessage04(ActionEvent e) {
		String[] options ={"예", "아니오"};
		int res = JOptionPane.showOptionDialog(this, "수업마칠까요?", "title", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
		JOptionPane.showMessageDialog(null, options[res]+"선택하셨습니다.");
	}
	protected void actionPerformedBtnMessage05(ActionEvent e) {
		String[] selectionValues = {"우유", "콜라", "커피"};
		String res = (String)JOptionPane.showInputDialog(this, "후식을 선택하시오", "후식", JOptionPane.INFORMATION_MESSAGE, null, selectionValues, selectionValues[0]);
		JOptionPane.showMessageDialog(this, res);
	}
	protected void actionPerformedBtnMessage06(ActionEvent e) {
		String res = (String)JOptionPane.showInputDialog(this, "후식을 선택하시오", "후식", JOptionPane.INFORMATION_MESSAGE, null, null, "아이스크림");
		JOptionPane.showMessageDialog(this, res);
	}	
}
